CREATE TABLE [dbo].[DocumentStorage]
(
[DocumentStorageKey] [uniqueidentifier] NOT NULL,
[Name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Description] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FileTypeCode] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[UpdatedOn] [datetime] NOT NULL,
[UploadedByUserKey] [uniqueidentifier] NULL,
[UploadedOn] [uniqueidentifier] NULL,
[Blob] [image] NULL,
[MarkedForDeleteOn] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[DocumentStorage] ADD CONSTRAINT [PK_DocumentStorage] PRIMARY KEY CLUSTERED ([DocumentStorageKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocumentStorage_CreatedByUserKey] ON [dbo].[DocumentStorage] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocumentStorage_FileTypeCode] ON [dbo].[DocumentStorage] ([FileTypeCode]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocumentStorage_UpdatedByUserKey] ON [dbo].[DocumentStorage] ([UpdatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DocumentStorage_UploadedByUserKey] ON [dbo].[DocumentStorage] ([UploadedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DocumentStorage] ADD CONSTRAINT [FK_DocumentStorage_FileTypeRef] FOREIGN KEY ([FileTypeCode]) REFERENCES [dbo].[FileTypeRef] ([FileTypeCode])
GO
ALTER TABLE [dbo].[DocumentStorage] ADD CONSTRAINT [FK_DocumentStorage_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[DocumentStorage] ADD CONSTRAINT [FK_DocumentStorage_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[DocumentStorage] ADD CONSTRAINT [FK_DocumentStorage_UserMain_UploadedBy] FOREIGN KEY ([UploadedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO